<?php
include_once('../includes/definer.php');
include_once(INC.'php/bootstrap.php');

$slider = Slider::getInstance();

//imagenes
if (isset($_POST['imgprefix'])) {
    $i=Imagen::lastId();
    foreach (glob(INC.'../content/tmp/slider/thumb/'.$_POST['imgprefix'].'-*') as $img) {
        $i++;
        $imageName = str_replace(INC.'../content/tmp/slider/thumb/', '', $img);
        $imageModel = Doctrine::getTable('imagen')->findOneBySrc($imageName);
        $imageModel->src = 'slider.'.$i.'.jpg';
        $imageModel->slider = $slider;
        $imageModel->save();
        rename(INC.'../content/tmp/slider/'.$imageName, INC.'../content/slider/slider.'.$i.'.jpg');
        rename(INC.'../content/tmp/slider/thumb/'.$imageName, INC.'../content/slider/thumb/slider.'.$i.'.jpg');
    }
}

header('location: '.URL.'slider#edit');
?>
